﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Wechat.API.Filter;
using Wechat.Dto.Request;
using Wechat.Dto.Search;
using Wechat.Manager;
using Wechat.Util.ReturnMessage;
using Wechat.Util.StateCode;

namespace Wechat.API.Controllers
{
    [RoutePrefix("api/replymsg"), UnUserAuthorize]
    public class ReplyMsgController : ApiController
    {
        #region 属性
        public IReplyMsgManager ReplyMsgManager { get; set; }

        #endregion

        #region 添加微信回复消息
        /// <summary>
        /// 添加微信回复消息
        /// </summary>
        /// <returns></returns>
        [Route("addreply"), HttpPost]
        public ResultMessage AddReply(ReplyMsgRequest request)
        {
            ResultMessage returnMsg = new ResultMessage()
            {
                Status = false
            };
            if (ModelState.IsValid)
            {
                returnMsg = ReplyMsgManager.ReplyMsgInsert(request);
            }
            else
            {
                returnMsg.Code = (int)EnumApiStateCode.ParameterValidationFailed;
                returnMsg.Message = "参数校验失败";
            }
            return returnMsg;
        }
        #endregion

        #region 删除微信回复消息
        /// <summary>
        /// 删除微信回复消息
        /// </summary>
        /// <returns></returns>
        [Route("deletereply"), HttpDelete]
        public ResultMessage DeleteReply(string ids)
        {
            ResultMessage returnMsg = new ResultMessage()
            {
                Status = false
            };
            if (ModelState.IsValid)
            {
                returnMsg = ReplyMsgManager.ReplyMsgDeleteById(ids);
            }
            else
            {
                returnMsg.Code = (int)EnumApiStateCode.ParameterValidationFailed;
                returnMsg.Message = "参数校验失败";
            }
            return returnMsg;
        }
        #endregion

        #region 修改微信回复消息

        /// <summary>
        /// 修改微信回复消息
        /// </summary>
        /// <returns></returns>
        [Route("updatereply"), HttpPost]
        public ResultMessage UpdateReply(ReplyMsgRequest request)
        {
            ResultMessage returnMsg = new ResultMessage()
            {
                Status = false
            };
            if (ModelState.IsValid)
            {
                if ((request.Id ?? 0) != 0)
                {
                    returnMsg = ReplyMsgManager.ReplyMsgUpdateById(request);
                }
                else
                {
                    returnMsg.Code = (int)EnumApiStateCode.ParameterValidationFailed;
                    returnMsg.Message = "参数校验失败";
                }
            }
            else
            {
                returnMsg.Code = (int)EnumApiStateCode.ParameterValidationFailed;
                returnMsg.Message = "参数校验失败";
            }
            return returnMsg;
        }
        #endregion

        #region 获取微信回复消息列表
        /// <summary>
        /// 获取微信回复消息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("getreplypage"), HttpGet]
        public ResultMessage GetReplyPageList([FromUri]ReplyMsgSearch request)
        {
            return ReplyMsgManager.GetReplyMsgPageData(request);
        }
        #endregion
    }
}
